package com.springboot.test;

import com.springboot.controller.CustomerTicketController;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

import static org.mockito.BDDMockito.given;

@RunWith(SpringRunner.class)
@WebMvcTest(CustomerTicketController.class)
public class CustomerControllerTestsWithMockMvc {
 
    @Autowired
    private MockMvc mvc;
 
    @MockBean
    private CustomerTicketController customerTicketController;
 
    @Test
    public void testGenerateCustomerTicket() throws Exception {

        String id = "1";

        given(this.customerTicketController.getById(id))
                .willReturn("mock-order-"+id);

        this.mvc.perform(MockMvcRequestBuilders.get("/ticket/getById/1")).andExpect(MockMvcResultMatchers.content().string("mock-order-"+id));
    }
}